package com.twu.biblioteca.model;

/**
 * Created by sgreweni on 22/07/2014.
 */
public class Book extends LibraryItem{
    private final String author;
    private final int yearPublished;

    public Book(String title, String author, int yearPublished){
        super(title);
        this.author = author;
        this.yearPublished = yearPublished;
    }

    public String getAuthor() {
        return author;
    }

    public int getYearPublished() {
        return yearPublished;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Book)) return false;
        if (!super.equals(o)) return false;

        Book book = (Book) o;

        if (yearPublished != book.yearPublished) return false;
        if (author != null ? !author.equals(book.author) : book.author != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (author != null ? author.hashCode() : 0);
        result = 31 * result + yearPublished;
        return result;
    }
}
